<?php
namespace Client\Controller;
use Think\Controller;
class KehuController extends BaseController{
//class KehuController extends Controller{
	
	//========================
	protected function _initialize(){
		parent::_initialize();
		header("Content-Type: text/html;charset=utf-8");
		$this->assign('tj',time());
		$this->assign('session',$_SESSION);
		
		//p($_SESSION);
		
	}
	
	
    public function index(){
    	
		$data=M('bb_shop')->select();
		$this->assign('cache',$data);
		$this->display();
    }
	
	
	
	public function addkehu(){
		if(IS_POST){
			if($_SESSION['wz']){
				$p=I('post.');
				$p['gps_lat']=$_SESSION['wz']['latitude'];
				$p['gps_lon']=$_SESSION['wz']['longitude'];
				$p['gps_address']=$_SESSION['wz']['address'];
				$p['provCn']=$_SESSION['wz']['province'];
				$p['cityCn']=$_SESSION['wz']['city'];
				$p['areaCn']=$_SESSION['wz']['district'];
				$agent=M('bb_agent')->where(array('openid'=>$_SESSION['openid']))->find();
				$p['creator']=$agent['realname'];
				$p['createtm']=date("Y-m-d H:i:s",time()); 
				$p['createip']=get_client_ip();
				$p['password']=md5($p['password']);
				$re=M('bb_shop')->add($p);
				if($re){
					$sv['id']=$re;
					$sv['shopid']='shop'.$re;
					$res=M('bb_shop')->save($sv);
					if($res){
						$info['status']=1;
						$info['msg']='添加成功！';
					}else{
						$info['status']=0;
						$info['msg']='添加失败！';
					}
				}else{
					$info['status']=0;
					$info['msg']='添加失败！';
					//header("location: http://wx.tingzan88.com/Client/Kehu");
				}
				$this->ajaxreturn($info);
			}
		}else{
			$this->display();
		}
	}
	
	
}